package logic

import (
	"context"
	"errors"
	"month2/B/rpc_B/model/mysql"

	"month2/B/rpc_B/internal/svc"
	"month2/B/rpc_B/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *user.GoodsAddRequest) (*user.GoodsAddResponse, error) {
	g := mysql.Goods2{
		GoodsName:  in.GoodsName,
		GoodsPrice: float64(in.GoodsPrice),
		GoodsNum:   int(in.GoodsNum),
		GoodsImg:   in.GoodsImg,
		Status:     int(in.Status),
	}
	err := g.GoodsAdd()
	if err != nil {
		logx.Error("产品发布失败")
		return nil, errors.New("产品发布失败")
	}
	return &user.GoodsAddResponse{
		GoodsId: int64(g.ID),
	}, nil
}
